package com.tzxs.pay.main.installment;

import android.app.Application;

import com.tzxs.pay.main.bill.model.CollectionBillEntity;
import com.tzxs.pay.main.installment.model.InstallBean;
import com.tzxs.pay.util.ISharedPreference;
import com.tzxs.pay.util.RetrofitUtil;
import com.tzxs.pay.util.RxUtil;
import com.tzxs.pay.util.netnavigator.NetNavigator;
import com.tzxs.pay.util.netnavigator.SimpleNetNavigator;

import java.lang.ref.WeakReference;

import retrofit2.Response;


//
public class InstallDataResource {
    private static InstallDataResource INSTANCE;
    private WeakReference<Application> app;
    //获取本地存储类对象
    private ISharedPreference sharedPreference;

    private InstallDataResource(WeakReference<Application> app) {
        this.app = app;
        sharedPreference = ISharedPreference.getInstance(app.get());
    }

    //获取单例
    public static InstallDataResource getINSTANCE(Application application) {
        if (INSTANCE == null) {
            synchronized (InstallDataResource.class) {
                if (INSTANCE == null) {
                    INSTANCE = new InstallDataResource(new WeakReference<>(application));
                }
            }
        }
        return INSTANCE;
    }


    /**
     * 开始花呗分期
     *
     * @param amount     分期金额
     * @param installNum 分期数
     * @param code       扫描支付宝二维码返回码
     * @param money      手续费
     */
    public void startScanInstall(String amount, int installNum, String code, int money, NetNavigator<InstallBean> navigator) {
        RxUtil.ioMain(RetrofitUtil.getInstance().apiService
                .scanInstall(sharedPreference.getToken(),
                        code, amount, installNum, money), navigator);

    }
}
